<?php

namespace app\purchase\model;

class User extends \ShopModel
{
    protected $table = 'sh_user';

    protected $pk = 'user_id';

    protected $autoWriteTimestamp = true;
    protected $updateTime = false;
    protected $createTime = 'create_at';


    /**
     * 生成密码盐
     */
    public function generateSalt()
    {
        $str = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
        $strMaxIndex = strlen($str) - 1;
        $salt = '';
        $saltLenght = 6;
        for ($i = 0; $i < $saltLenght; $i ++) {
            $salt[$i] = $str[mt_rand(0, $strMaxIndex)];
        }
        return $salt;
    }

    public function getLastLoginAttr($time)
    {
        return date('Y-m-d H:i:s', $time);
    }

    public function getLastLoginH5Attr($time)
    {
        return date('Y-m-d H:i:s', $time);
    }

    public function orders(){
        return $this->hasMany('Order','order_id');
    }

}
